﻿<UserControl x:Class="FileExplorer.View.DirectoryViewer"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:local="clr-namespace:ThumbGen"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/CommonStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <local:BackdropConverter x:Key="BackdropConverter"/>
            <local:ImageLockFixConverter x:Key="ImageLockFixConverter"/>
            <BooleanToVisibilityConverter x:Key="Bool2VisibConverter"/>
            <Style x:Key="selectedDirStyle">
                <!--<Style.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected, FallbackValue={x:Null}}" Value="True" >
                        <Setter Property="StackPanel.Background" Value="LightGray" ></Setter>
                    </DataTrigger>
                </Style.Triggers>-->
            </Style>

            <Style TargetType="{x:Type ListBoxItem}">
                <Style.Resources>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
                </Style.Resources>
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                <Setter Property="VerticalContentAlignment" Value="Stretch"/>
            </Style>

            <!-- Style for folder/file name text block -->
            <Style x:Key="NormalTextBlockStyle">
                <!--<Setter Property="TextBlock.Width" Value="120"></Setter>-->
                <Setter Property="TextBlock.TextWrapping" Value="NoWrap"></Setter>
                <Setter Property="TextBlock.TextTrimming" Value="CharacterEllipsis"></Setter>
                <Setter Property="TextBlock.VerticalAlignment" Value="Center"></Setter>
            </Style>

            <!-- Style for folder/file type and size text block -->
            <Style x:Key="FadedTextBlockStyle" BasedOn="{StaticResource NormalTextBlockStyle}">
                <Setter Property="TextBlock.Foreground" Value="DimGray"></Setter>
            </Style>

            <!-- Data template for displaying a directory or a file -->
            <DataTemplate x:Key="DirViewTemplate">
                <Label HorizontalAlignment="Left" Cursor="Hand"
                   Background="Transparent" 
                   DataContext="{Binding}"
                   IsTabStop="True" BorderThickness="1">
                    <Label.Content>
                        <StackPanel Orientation="Vertical">
                            <DockPanel>
                                <Image DockPanel.Dock="Left" VerticalAlignment="Center"
                               x:Name="img" 
                               Margin="5" Source="{Binding ImgSource, Converter={StaticResource ImageLockFixConverter}, ConverterParameter=70}" 
                               Width="70" Height="100" />
                                <StackPanel DockPanel.Dock="Left" VerticalAlignment="Center" HorizontalAlignment="Left" 
                                    x:Name="ObjInfoPanel">
                                    <!--<TextBlock x:Name="ObjName" Margin="5 5 5 0"
                                       FontWeight="Bold" 
                                       Text="{Binding Name}" 
                                       Style="{StaticResource NormalTextBlockStyle}"/>-->
                                    <TextBlock x:Name="ObjType" Margin="5 0 5 0"
                                       Style="{StaticResource FadedTextBlockStyle}"/>
                                    <TextBlock x:Name="ObjSize" Margin="5 0 5 5"
                                       HorizontalAlignment="Left"
                                       Style="{StaticResource FadedTextBlockStyle}"/>
                                    <local:FileInfoControl VerticalAlignment="Center" Margin="5 0 0 0" Height="18"
                                          HasExternalSubtitles="{Binding HasExternalSubtitles}" HasMovieInfo="{Binding HasMovieInfo}" HasMoviesheet="{Binding HasMoviesheet}"
                                                       HasMoviesheetMetadata="{Binding HasMoviesheetMetadata}"/>
                                </StackPanel>

                            </DockPanel>
                            <TextBlock x:Name="ObjName1" Margin="5 5 5 0"
                                       FontWeight="Bold" 
                                       Text="{Binding Name}" 
                                       Style="{StaticResource NormalTextBlockStyle}"/>
                        </StackPanel>
                    </Label.Content>
                    <Label.ToolTip>
                        <ToolTip Name="FileInfo" Placement="Mouse">
                            <StackPanel Orientation="Vertical">
                                <TextBlock FontWeight="Bold" Text="{Binding Name}"/>
                                <TextBlock Text="Double-Click to play using default player" Margin="0 3 0 0"/>
                            </StackPanel>
                        </ToolTip>
                    </Label.ToolTip>
                </Label>

                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding Path=DirType}" Value="Directory">
                        <!--<Setter Property="Image.Source" TargetName="img" Value="/Images/folder.png"></Setter>-->
                        <Setter Property="Text" TargetName="ObjType" Value="File Folder"></Setter>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=DirType}" Value="Diskdrive">
                        <!--<Setter Property="Image.Source" TargetName="img" Value="/Images/folder.png"></Setter>-->
                        <Setter Property="Text" TargetName="ObjType" Value="{Binding Ext}"></Setter>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=DirType}" Value="File">
                        <!--<Setter Property="Image.Source" TargetName="img" Value="/Images/file.png"></Setter>-->
                        <Setter Property="Text" TargetName="ObjType" Value="{Binding Ext}"></Setter>
                        <Setter Property="Visibility" TargetName="ObjSize" Value="Visible"></Setter>
                        <Setter Property="Text" TargetName="ObjSize" Value="{Binding Size}"></Setter>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected, FallbackValue={x:Null}}" Value="True" >
                        <!--<Setter Property="Background" TargetName="ObjInfoPanel" Value="Gray" ></Setter>-->
                        <!--<Setter Property="Foreground" TargetName="ObjName" Value="Gray" ></Setter>-->
                        <Setter Property="Foreground" TargetName="ObjType" Value="Black" ></Setter>
                        <Setter Property="Foreground" TargetName="ObjSize" Value="Black" ></Setter>
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Border Background="White">
            <Border.Style>
                <Style>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=BackdropImage,Path=Source,FallbackValue={x:Null}}" Value="{x:Null}">
                            <Setter Property="Border.Visibility" Value="Collapsed"/> 
                        </DataTrigger>
                    </Style.Triggers>
                    <Setter Property="Border.Visibility" Value="Visible"/>
                </Style>
            </Border.Style>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Image x:Name="BackdropImage" Stretch="Uniform" Margin="5" Source="{Binding Path=CurrentDirectory.Path,Converter={StaticResource BackdropConverter},FallbackValue={x:Null}}">
                </Image>
                <Button Margin="2 2 5 2" Click="PreviewImageButton_Click" ToolTip="Preview full moviesheet" VerticalAlignment="Center" 
                        Grid.Row="1" HorizontalAlignment="Right">
                    <Image Source="/images/view.png" VerticalAlignment="Center" Width="16" Height="16"/>
                </Button>
            </Grid>
            
        </Border>
        <local:MediaInfoControl Grid.Row="1" x:Name="TheMediaInfoControl" Visibility="Visible"
                                VerticalAlignment="Stretch" HorizontalAlignment="Stretch">

        </local:MediaInfoControl>

        <ListBox x:Name="dirList" Grid.Row="1" FocusVisualStyle="{x:Null}"
                 ItemsSource="{Binding Path=CurrentItems}" 
                 ItemTemplate="{StaticResource DirViewTemplate}" BorderThickness="0" 
                 HorizontalContentAlignment="Left" VerticalContentAlignment="Top" 
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                 SelectedItem="{Binding Path=DirViewVM.CurrentItem,Mode=OneWayToSource}"
                 MouseDoubleClick="dirList_MouseDoubleClick"
                 KeyDown="dirList_KeyDown">
            <ListBox.Style>
                <Style>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding CurrentDirectory.DirType}" Value="File">
                            <Setter Property="ListBox.Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ListBox.Style>
            <ListBox.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightGray" Opacity="0.5"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Transparent"/>
            </ListBox.Resources>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Orientation="Horizontal" ItemWidth="220"></WrapPanel>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemContainerStyle>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                    <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                </Style>
            </ListBox.ItemContainerStyle>
        </ListBox>
    </Grid>
</UserControl>

    